var fs = require("fs");
var _ = require("lodash");

let fileNameC = "Summons";
let fileName1 = "SummonDes";
let fileName2 = "AuraDes";
let fileName3 = "./data/skill4";
let outputFileName = "./data/summon.json";

let mainData = JSON.parse(fs.readFileSync(`${fileNameC}.json`).toString()).map;
let SummonDes = JSON.parse(fs.readFileSync(`${fileName1}.json`).toString()).map;
let AuraDes = JSON.parse(fs.readFileSync(`${fileName2}.json`).toString()).map;
let skillDes = JSON.parse(fs.readFileSync(`${fileName3}.json`).toString());

let SummonDesMap = new Map();
let AuraDesMap = new Map();
let skillMap = new Map();
_.forEach(SummonDes, (e) => {
  let id = e.id;
  let data = e.data;
  SummonDesMap.set(id, data);
});
_.forEach(AuraDes, (e) => {
  let id = e.id;
  let data = e.data;
  AuraDesMap.set(id, data);
});
_.forEach(skillDes, (e) => {
  let id = e.id;
  let data = e.data;
  skillMap.set(id, data);
});
_.forEach(mainData, (e) => {
  e.data.summonStage = _.map(e.data.summonStage, (x) => {
    if (skillMap.has(x.summonSkill)) {
      x.summonSkill = skillMap.get(x.summonSkill);
    }
    if (skillMap.has(x.supportSkill)) {
      x.supportSkill = skillMap.get(x.supportSkill);
    }
    return x;
  });
  let aura = e.data.summonAura;
  if (AuraDesMap.has(aura)) {
    e.data.summonAura = AuraDesMap.get(aura);
  }
  let id = e.data.id;
  if (SummonDesMap.has(id)) {
    _.assign(e.data, SummonDesMap.get(id));
  }
});

fs.writeFileSync(outputFileName, JSON.stringify(mainData));
